package com.lz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lz.domain.MyUserDetails;
import com.lz.domain.User;
import com.lz.service.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <pre>
 * @描述：获取用户的详细信息（账号密码和权限）
 * @作者：lizhao
 * @创建时间： 2024/8/19 下午3:07
 * </pre>
 **/
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Resource
    public UserService userService;

    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUsername, s);
        User one = userService.getOne(wrapper);
        if (one == null) {
            throw new UsernameNotFoundException(s);
        }
        return new MyUserDetails(one);
    }
}
